<template>
	<div>
		<van-nav-bar
		  title="登录"
		  left-arrow
		  @click-left="onClickLeft"
		  :fixed=true
		  class="away"
		/>
		<van-cell-group>
		  <van-field
		    v-model="username"
		    required
		    clearable
		    label="用户名"
		    placeholder="请输入用户名"
			class="away up"
		  />
		
		  <van-field
		    v-model="password"
		    label="密码"
		    placeholder="请输入密码"
		    required
			class="away"
		  />
		</van-cell-group>
		<van-button type="primary" size="large" class="away" @click="login">登录</van-button>
		<span class="text">没有账号？</span><van-button type="info" to="/register">去注册</van-button>
		<h3>{{this.$store.state.uid}}</h3>
		<h3>{{this.$store.state.token}}</h3>
	</div>
</template>

<script>
	export default{
		name:"login",
		methods:{
			onClickLeft(){
				this.$router.go(-1)
			}
		},
		data(){
			return {
				username:"",
				password:""
			}
			
		},
		updated() {
			this.$store.dispatch("getloginmsg",{username:this.username,password:this.password})
			this.$store.commit("getnames",{username:this.username})
			this.$store.commit("getpsds",{password:this.password})
		},
		methods:{
			onClickLeft(){
				this.$router.go(-1)
			},
			
			login(){
				// this.$router.go(0)
				
				alert(this.$store.state.userObj.msg)
				if(this.$store.state.userObj.msg=="登录成功"){
					
					this.$router.push("/home")
				}else{
					return false
					
				}
				
			}
		}
	}
</script>

<style scoped="">
	.away{
		margin-bottom: 70px;
	}
	.text{
		font-size: 18px;
		color: red;
		margin-right: 30px;
	}
	.up{
		margin-top: 90px;
	}
</style>
